package com.comba.nutz.boot.demo;

import com.comba.nutz.boot.demo.service.impl.BannerServiceImpl;
import com.comba.nutz.boot.starter.dao.SpringNutDao;
import com.comba.nutz.boot.starter.datasource.TargetDataSource;
import org.nutz.json.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangjunpeng on 2018/5/22.
 */
@RestController
@SpringBootApplication
@ComponentScan(value = "com.comba")
@EnableTransactionManagement
public class NutzBootDemoApplicaton {

    @Autowired
    SpringNutDao springNutDao;

    @Autowired
    BannerServiceImpl bannerService;

    @GetMapping("test")
    public String test() {
        return Json.toJson(springNutDao.queryBySql("select * from device_info", new HashMap<>(), null));
    }

    @GetMapping("testService")
    public String testService() {
        return Json.toJson(bannerService.query());
    }

    @GetMapping("testSql")
    @TargetDataSource("ds1")
    public String testSql() {
        Map<String, Object> params = new HashMap<>();
        params.put("name", null);

        return Json.toJson(springNutDao.queryBySqlKey("listAccessRecord", params, null));
    }

    public static void main(String args[]) {
        SpringApplication.run(NutzBootDemoApplicaton.class, args);
    }
}
